/*
Philip Dilse
dilsep
Assignment 3

unit test for shuffle()
*/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "dominion.h"
#include "dominion_helpers.h"

int main() {
    int i, j;
    struct gameState *gs = newGame();
    int randomCard;
    int player = 0;
    int cardCount[treasure_map + 1];

    // set up random number gen
    srand(time(NULL));

    for (i = 1; i <= MAX_DECK; i++) {
        gs->deckCount[player] = i;

        // init card counts to zero
        for (j = 0; j < treasure_map + 1; j++) {
            cardCount[j] = 0;
        }

        // randomly assign cards to deck
        for (j = 0; j < i; j++) {
            randomCard = rand() % (treasure_map + 1);
            gs->deck[player][j] = randomCard;
            cardCount[randomCard]++;
        }

        // shuffle deck
        shuffle(player, gs);

        // subtract cards in new deck from cardCount, should all be zero when done
        for (j = 0; j < i; j++) {
            cardCount[gs->deck[player][j]]--;
        } 

        // check that counts are all zero
        for (j = 0; j < treasure_map + 1; j++) {
            if (cardCount[j] != 0) {
                printf("shuffle() error: deckCount=%d\n", i);
                break;
            }
        }
    }

    free(gs);
    return 0;
}
